package com.bawei.mall.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bawei.common.security.utils.SecurityUtils;
import com.bawei.mall.product.domain.MallProductShoppingCart;
import com.bawei.mall.product.domain.model.ShoppingCartModel;
import com.bawei.mall.product.mapper.MallProductShoppingCartMapper;
import com.bawei.mall.product.service.IMallProductShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName IMallProductShoppingCartServiceImpl
 * @Description 描述
 * @Author ZiZheng.Li
 * @Date 2024/7/5 17:20
 */
@Service
public class IMallProductShoppingCartServiceImpl extends ServiceImpl<MallProductShoppingCartMapper,MallProductShoppingCart> implements IMallProductShoppingCartService {
    @Autowired
    private MallProductShoppingCartMapper mallProductShoppingCartMapper;

    /**
     * 查询购物车列表
     * @return
     */
    @Override
    public List<ShoppingCartModel> queryList() {
        Long userId = SecurityUtils.getUserId();

        List<ShoppingCartModel> shoppingCartModels = mallProductShoppingCartMapper.queryList(userId);
        shoppingCartModels.forEach(shoppingCartModel -> {
            shoppingCartModel.setProductAttr("[{\"key\":\"颜色\",\"value\":\"黑色\"},{\"key\":\"容量\",\"value\":\"128G\"}]");
        });
        return shoppingCartModels;
    }
}
